package com.example.test3;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Service
public class DataService {
    @Autowired
    GetCSVData getCSVData;
    List<RegionStates> list;

    public List<RegionStates> getAll() throws IOException{
        return getCSVData.getData();
    }

    public List<RegionStates> getByState(String state) throws IOException{
         list = getCSVData.getData();
        List<RegionStates> filteredList = new ArrayList<>();
        for (RegionStates item : list){
            if(item.getState().equals(state)){
                filteredList.add(item);
            }
        }
        return filteredList;
    }

    public List<RegionStates> getByCountry(String country) throws IOException{
        list = getCSVData.getData();
        List<RegionStates> filteredList = new ArrayList<>();
        for (RegionStates item : list){
            if(item.getCountry().equals(country)){
                filteredList.add(item);
            }
        }
        return filteredList;
    }
}
